package com.myjoje.controller.system;

import com.myjoje.base.BaseController;
import com.myjoje.bean.system.MenuBean;
import com.myjoje.service.system.MenuService;
import com.myjoje.util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/menu")
public class MenuController extends BaseController {

    @Autowired
    private MenuService menuService;


    /**
     * 保存或更新菜单
     */
    @RequestMapping("/saveOrUpdateMenu")
    public Object saveOrUpdateMenu(MenuBean bean) {
        return menuService.saveOrUpdateMenu(bean);
    }

    /**
     * 菜单分页数据
     */
    @RequestMapping("/getMenuPagingData")
    public Object getMenuPagingData(String sContent, Integer currentPage, Integer pageSize) {
        List<MenuBean> rows = menuService.getMenuList(sContent, currentPage, pageSize);
        Long total = menuService.getMenuCount(sContent);
        return Message.success("请求成功", getPagingData(rows, total));
    }

    /**
     * 菜单列表
     */
    @RequestMapping("/deleteMenu")
    public Object deleteMenu(String id) {
        return menuService.deleteMenu(id);
    }

    /**
     * 菜单树形结构
     */
    @RequestMapping("/getMenuTree")
    public Object getMenuTree() {
        return menuService.getMenuTree();
    }

    /**
     * 根据角色获取菜单
     */
    @RequestMapping("/getMenuByRole")
    public Object getMenuByRole(String roleId) {
        return menuService.getMenuIdsByRole(roleId);
    }

    /**
     * 保存菜单角色对应关系
     */
    @RequestMapping("/saveMenuRole")
    public Object saveMenuRole(String roleId, String menuIds) {
        return menuService.saveMenuRole(roleId, menuIds);
    }


}
